using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Pokemon
{
    public class ItemManager
    {
        #region Attribute

        private static List<Item> _items = new List<Item>();

        private static List<Item> _deletedItems = new List<Item>();

        #endregion

        #region Method
        /// <summary>
        /// Add a new item to item list, especally it appear on game play screean
        /// </summary>
        /// <param name="item">item that we want to add</param>
        public static void Add(Item item)
        {
            _items.Add(item);
        }

        /// <summary>
        /// Remove an item when the item has acted
        /// </summary>
        /// <param name="item">item that we want to remove</param>
        public static void Remove(Item item)
        {
            _deletedItems.Add(item);
        }

        /// <summary>
        /// Update item list, remove all has been deleted in item list and update themself        
        /// </summary>
        /// <param name="gameTime"></param>
        public static void Update(GameTime gameTime)
        {
            foreach (var item in _deletedItems)
            {
                _items.Remove(item);
            }
            _deletedItems.Clear();

            foreach (var item in _items)
            {
                item.Update(gameTime);
            }
        }


        /// <summary>
        /// After we update the item list, we invoke this function to draw all existent items in the item list
        /// </summary>
        /// <param name="gameTime"></param>
        public static void Draw(GameTime gameTime)
        {
            foreach (var item in _items)
            {
                item.Draw(gameTime);
            }
        }
        #endregion



    }
}
